package org.example;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@ComponentScan(basePackages = "com.zy.bean")  //spring容器启动时，扫描com.zy.bean包，
// 只要有 @Component    // <bean id="product" class="com.zy.bean.Product" />
// 则托管.
public class AppConfig2 {

    //托管一个线程池
    @Bean   //主要用于托管第三方的类, 如一个线程池ThreadPool
    public Executor threadPool(){
        //10 基础线程数
        //20： 最多的线程数
        // 10+seconds  线程最大存活时间
        // 阻塞队列:  阻塞, 有界, 队列
        Executor executor=new ThreadPoolExecutor(10,20,10, TimeUnit.SECONDS,new ArrayBlockingQueue<>(10));
        return executor;
    }
}
